<?php

class Controller_Admin_Post_Create extends Controller_Admin_Abstract
{
	function execute($request)
	{
		$form = new Form_Admin_Post_Create;

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getValues();

			$item = Mongo_Document::factory('post');

			$item -> _id = $item -> collection() -> get_auto_increment();

			$item -> title = $data['title'];
			$item -> tags = $data['tags'];
			$item -> content = $data['content'];
			$item -> created_at = time();
			$item -> updated_at = time();
			$item -> view_count = 0;

			$item -> created_by = Agilet::getViewer() -> _id;

			$item -> save();

			Agilet::redirect('admin/post');
		}

		$request -> response = View::render($data = array('form' => $form), $script = 'controller/admin/edit.tpl');
	}

}
